package pacmanreturns;

import java.awt.*;

class Ghost extends Sprite {

	public static final int WIDTH = 18;
	public static final int HEIGHT = 18;
	public static Color ghostColor = null;

	public Ghost(Game inCanvas, Maze inMaze) {
		super(inCanvas, inMaze);
	}
	
	private void checkBounds() {
		if (x < (0 - WIDTH)) {
			x = Game.WIDTH;
		} else if (x > Game.WIDTH) {
			x = (0 - WIDTH);
		} else if (y < (0 - HEIGHT)) {
			y = Game.HEIGHT;
		} else if (y > Game.HEIGHT) {
			y = (0 - HEIGHT);
		}
	}

	public void move() {
		if (maze.canGo(nextDirection, x, y)) {
			direction = nextDirection;
			nextDirection = Game.STOP;
		}
		if (!maze.isSpace(direction, x, y)) {
			return;
		}
		switch (direction) {
			case Game.RIGHT: x += maze.SPEED; break;
			case Game.UP:    y -= maze.SPEED; break;
			case Game.LEFT:  x -= maze.SPEED; break;
			case Game.DOWN:  y += maze.SPEED; break;
			default: break;
		}
		checkBounds();
		maze.removeDot(direction, x, y);
	}

	public void draw() {
		move();

		canvas.setColor(COLOR);
		canvas.arc(x + 1, y + 1, WIDTH, HEIGHT,  0, 360);
	}
}